package condominio.servlet.residente;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import condominio.excepcion.DAOExcepcion;
import condominio.negocio.GestionResidente;


/**
 * Servlet implementation class ResidenteInsertarServlet
 */
@WebServlet("/ResidenteInsertarServlet")
public class ResidenteInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ResidenteInsertarServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String x = request.getParameter("dni");
		String y = request.getParameter("nombre");
		String w = request.getParameter("correo");
		String z = request.getParameter("password");
		
		GestionResidente negocio = new GestionResidente();
		try {
			negocio.insertar(x, y, w, z);
			/**response.sendRedirect(request.getContextPath()	+ "/RolBuscarServlet");*/
			response.sendRedirect(request.getContextPath() + "/ResidenteNuevo.jsp");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
